<template>
	<view>
		<view class="top">
			<view class="search">
				<view class="search_input">
					<image src="/static/images/search.png"></image>
					<input type="text" :value="name" placeholder="请输入关键词" @input="getInputValue"/>
				</view>
				<view class="search_btn" @tap="getData(1)">搜索</view>
			</view>
		</view>
		
		<view class="user_box">
			<block v-for="(item,index) in list">
				<view class="user_item" @tap="prompt()">
					<image :src="item.avatar" mode="aspectFill"></image>
					<view>{{item.name}}</view>
					<view class="">{{item.username}}</view>
				</view>
			</block>
			<view class="add_prompt" v-if="loading">此处可搜索全公司所有业务客户，防止撞单</view>
		</view>
		
		<Loading ref="load"></Loading>
	</view>
</template>

<script>
	import Loading from "../../../components/loading/loading.vue"
	export default{
		components:{
			Loading
		},
		data(){
			return{
				loading:true,
				page:1,
				list:[]
			}
		},
		onLoad() {
			
		},
		onReachBottom() {
			if(this.loading){
				this.getData(1)
			}
		},
		methods:{
			getData(type){//搜索
				if(type == 1){this.page = 1,this.list = [];this.loading = true}
				this.$refs.load.initLoading({loadType:type}).then(res =>{
					this.$api.getRepeatCustomer({search:this.name,page:this.page}).then(res=>{
						this.$refs.load.getLoadingData({oldData:this.list,newData:res}).then(res =>{
							this.list = res.list;
							this.loading = res.loading;
							this.page ++;
						})
					})
				})
			},
			getInputValue(e){
				this.name = e.detail.value;
			},
			prompt(){
				uni.showModal({
					title:"",
					content:"此处是客户查重避免撞单，不能查看别人的客户资料",
					showCancel:false,
					confirmText:"我知道了"
				})
			}
		}
	}
</script>

<style>
	.top{position: fixed;height: 100upx;width: 100%;top: 0;left: 0;z-index: 998;}
	.user_box{margin-top: 100upx;background: #FFFFFF;}
	.add_prompt{text-align: center;}
</style>
